import textMap from "@/utils/TextMap.js"
import c from "@/utils/Constant.js"


function initNotice() {
	return {
		title: '系统通知',
		content: '',
		entity: '',
		jumpUrl: ''
	}
}

import listUtils from "@/utils/ListUtils.js"
const commentUrl = "#/" //评论详情的url
const topicUrl = "#/" //话题详情的url
export default {


	/*构建实体类型为主题的通知对象
	  除了标题需要自定义以外，其他的都属性都可以创建出来	
	*/
   /**
	* @param {Object} message   消息
	* @param {Object} topics    构建通知需要的实体集合
	* @param {Object} title     自定义通知的标题，看自己的需要
	*/
	buildTopicNotice(message, topics, title,content) {
		let msgCon = JSON.parse(message.content);
		let notice = initNotice();
		console.log(msgCon.entityId)
		let topic = listUtils.findElem(topics, "id", msgCon.entityId)
		let loginUser = uni.getStorageSync('user')
		console.log(topic)
		notice.title = title
		//通知内容
		notice.content = content
		if(topic == null){
			notice.entity = {
				nickname: loginUser.nickname,
				content: "话题已删除"
			}; 
		}else{
			notice.entity = {
				nickname: loginUser.nickname,
				content: topic.title
			}; 
			notice.jumpUrl = topicUrl + msgCon.entityId; //主题详情页面，并带上主题id
		}
		
		return notice;
	},
	
	//构建实体类型为评论的系统通知对象
	  /**
		* @param {Object} message   消息
		* @param {Object} topics    构建通知需要的实体集合
		* @param {Object} title     自定义通知的标题，看自己的需要
		* @param {Object} title     自定义通知的内容，看自己的需要
		*/
	buildCommentNotice(message,comments,title,content) {
		let msgCon = JSON.parse(message.content);
		let notice = initNotice();
		let loginUser = uni.getStorageSync('user')
		let comment = listUtils.findElem(comments, "id", msgCon.entityId)
		notice.title = title
		notice.content = content
		if(comment == null){
			notice.entity = {
				nickname: loginUser.nickname,
				content: "评论已删除"
			};
		}else{
			notice.entity = {
				nickname: loginUser.nickname,
				content: comment.replyText
			};
			notice.jumpUrl = commentUrl + msgCon.entityId; //主题详情页面，并带上评论id
		}
		
		return notice;
	},
}
